package com.app.mymusic.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import com.app.mymusic.utils.LogUtil;

/**
 * Created by Administrator on 2016/11/17.
 */

public class RadarView extends View{
    private int count = 6;
    private int mViewWidth;
    private int mViewHeight;
    private int r=30;
    private Paint mPaint;
    private Paint cPaint;
    private float angle = (float) (Math.PI*2/count);
    public RadarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint=new Paint();
        cPaint=new Paint();
        mPaint.setColor(Color.BLACK);
        cPaint.setColor(Color.BLUE);
        mPaint.setStrokeWidth(8);
        cPaint.setStrokeWidth(3);
        mPaint.setStyle(Paint.Style.STROKE);
        cPaint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Path path=new Path();
//        canvas.translate(mViewWidth/2,mViewHeight/2);
        for(int i=0;i<6;i++){
            if(i==0){
                path.moveTo(mViewWidth/2+r,mViewHeight/2);
            }else{
                float x= (float) (mViewWidth/2+Math.cos(i*angle)*r);
                float y= (float) (mViewHeight/2+Math.sin(i*angle)*r);
                LogUtil.showLog("x:"+x+"-Y:"+y);
                path.lineTo(x,y);
            }
        }
        path.close();
        canvas.rotate(120,50,50);
        canvas.drawCircle(mViewWidth/2,mViewHeight/2,20,cPaint);
        canvas.drawPath(path,mPaint);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mViewWidth=w;
        mViewHeight=h;
        LogUtil.showLog("w:"+w+"-h:"+h);
    }
}
